#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int* plusOne(int* digits, int digitsSize, int* returnSize) {
    int end = digitsSize - 1;
    int count = 0;
    int* ans = (int*)malloc(sizeof(int) * (digitsSize + 1));
    while (end >= 0)
    {
        if (digits[end] != 9)
        {
            break;
        }
        count++;
        end--;
    }
    if (count)
    {
        if (digitsSize - count != 0)
        {
            *returnSize = digitsSize;
            digits[end]++;
            for (int i = end + 1; i < digitsSize; i++)
            {
                digits[i] = 0;
            }
            memcpy(ans, digits, sizeof(int) * digitsSize);
        }
        else
        {
            *returnSize = digitsSize + 1;
            ans[0] = 1;
            memset(ans + 1, 0, sizeof(int) * digitsSize);
        }
    }
    else
    {
        *returnSize = digitsSize;
        digits[digitsSize - 1]++;
        memcpy(ans, digits, sizeof(int) * digitsSize);
    }
    return ans;
}

int main()
{
    int arr[] = { 9 };
    int sz = sizeof(arr) / sizeof(arr[0]);
    int i = 1;
    plusOne(arr, sz, &i);
	return 0;
}